package com.migo.utils.manager.factory;

import com.migo.common.SysOperLog;
import com.migo.thread.service.ISLSProducerLogService;
import com.migo.utils.AddressUtils;
import com.migo.utils.JsonUtils;
import com.migo.utils.spring.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.TimerTask;

/**
 * 异步工厂（产生任务用）
 *
 * @author liuhulu
 */
public class AsyncFactory {
    private static final Logger sys_user_logger = LoggerFactory.getLogger("sys-user");

    /**
     * 操作日志记录
     *
     * @param operLog 操作日志信息
     * @return 任务task
     */
    public static TimerTask recordOper(final SysOperLog operLog) {
        return new TimerTask() {
            @Override
            public void run() {
                // 远程查询操作地点
                operLog.setOperLocation(AddressUtils.getRealAddressByIP(operLog.getOperIp()));
                try {
                    SpringUtils.getBean(ISLSProducerLogService.class).sendSLSLogs("pvmg10", "applog", "topic1", "resource", JsonUtils.getJSONString(operLog));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };
    }

}
